<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>系统管理</el-breadcrumb-item>
      <el-breadcrumb-item>数据字典</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20" class="el-row-table">
        <el-col :span="12"
          ><div class="grid-content bg-purple">
            <el-input placeholder="请输入内容" clearable>
              <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input></div
        ></el-col>
        <el-col :span="4">
          <div class="grid-content bg-purple">
            <el-button type="primary" @click="toAddDict"
              >添加数据字典</el-button
            >
          </div>
        </el-col>

        <el-col :span="4">
          <div class="grid-content bg-purple">
            <el-button type="success" @click="getDataDictionaryList"
              >刷新</el-button
            >
          </div>
        </el-col>
      </el-row>

      <!-- 数据字典列表区域 -->
      <el-table border stripe width="100%" :data="dataDictionaryList">
        <el-table-column fixed label="序号" prop="id"> </el-table-column>
        <el-table-column fixed label="名称" prop="note"> </el-table-column>
        <el-table-column fixed label="关键字" prop="name"> </el-table-column>
        <el-table-column fixed label="操作">
          <template slot-scope="scope">
            <!-- 第一个是编辑数据字按钮 -->
            <el-tooltip
              effect="dark"
              content="编辑数据字典明细"
              placement="top"
              :enterable="false"
            >
              <el-button
                type="success"
                icon="el-icon-edit"
                circle
                @click="tocheckDictInfo(scope.row.id)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.current"
        :page-sizes="[5, 10]"
        :page-size="queryInfo.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
import { pageDict } from "@/api/datadictionary.js";
export default {
  data() {
    return {
      //获取用户列表的参数对象
      queryInfo: {
        current: 1,
        size: 5,
        name: "",
      },
      total: 0,

      dataDictionaryList: [],
      showDictDialogVisible: false,
      showForm: {},
    };
  },
  created() {
    this.getDataDictionaryList();
  },
  methods: {
    // 监听 pagesize 改变的事件
    handleSizeChange(newSize) {
      this.queryInfo.size = newSize;
      this.getDataDictionaryList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(newPage) {
      this.queryInfo.current = newPage;
      this.getDataDictionaryList();
    },

    async getDataDictionaryList() {
      const { data: res } = await pageDict(
        this.queryInfo.current,
        this.queryInfo.size
      );
      this.dataDictionaryList = res.data.records;

      this.total = res.data.total;
    },
    toAddDict() {
      this.$router.push("/sys/dict/add");
    },
    //跳转查看某条数据字典明细
    tocheckDictInfo(id) {
      localStorage.setItem("checkId", JSON.stringify(id));
      this.$router.push("/sys/dict/info");
    },
  },
};
</script>

<style lang="less" scoped>
.breadcrumb {
  margin-bottom: 15px;
  font-size: 15px;
}
.box-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
.el-row-table {
  margin-bottom: 15px !important;
}
.el-pagination {
  margin-top: 15px;
}
</style>